package com.dragon.pear.api.perfect;

import com.chris.dev.base.libs.v1.http.params.IdParam;
import com.chris.dev.base.libs.v1.http.params.IdsParam;
import com.chris.dev.base.libs.v1.http.protocols.HttpResult;
import com.chris.dev.base.libs.v1.http.results.ValueResult;
import com.chris.libs.http.x.v1.NetApi;
import com.dragon.pear.base.http.SuccessNetCallback;
import com.dragon.pear.base.http.DefaultRetrofit;
import com.dragon.pear.base.http.TokenUtil;
import com.dragon.pear.models.uaa.LoginByMobileVerifyCodeParam;
import com.dragon.pear.models.uaa.LoginResult;

import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;

/**
 * @author Chris Chan
 * Create on 2025-02-17 20:36
 * Use for: 账号 接口调用
 * Explain: 标准模式
 * 不用在调用的时候构建Token和body
 * 底部附有使用方法
 */
public class UaaAuthAccountApi extends NetApi {
    public static Service service = DefaultRetrofit.create("auth/account", Service.class);

    /**
     * 登录 手机号和验证码
     *
     * @param params
     * @param callback
     */
    public static void loginByMobileVerifyCode(LoginByMobileVerifyCodeParam params, SuccessNetCallback<LoginResult> callback) {
        RequestBody requestBody = postRequestObjBody(null, params);
        service.loginByMobileVerifyCode(requestBody).enqueue(callback);
    }

    /**
     * 注册 不可用
     *
     * @param params
     * @param callback
     */
    public static void reg(IdParam<Long> params, SuccessNetCallback<ValueResult<Boolean>> callback) {
        RequestBody requestBody = postRequestObjBody(null, params);
        service.reg(requestBody).enqueue(callback);
    }

    /**
     * 退出登录
     *
     * @param params
     * @param callback
     */
    public static void logout(IdsParam<Long> params, SuccessNetCallback<ValueResult<Boolean>> callback) {
        String token = TokenUtil.getAuthorization();
        RequestBody requestBody = postRequestObjBody(null, params);
        service.removeAllByIds(token, requestBody).enqueue(callback);
    }

    public interface Service {
        // 手机号和验证码登录
        @POST("loginByMobileVerifyCode")
        Call<HttpResult<LoginResult>> loginByMobileVerifyCode(@Body RequestBody body);

        // 注册
        @POST("reg")
        Call<HttpResult<ValueResult<Boolean>>> reg(@Body RequestBody body);

        // 退出登录
        @POST("logout")
        Call<HttpResult<ValueResult<Boolean>>> removeAllByIds(@Header("Authorization") String token, @Body RequestBody body);
    }
}
